#!/bin/sh

echo "Enter your username"
read -e name

echo "Enter your password"
read -es pass

FILE=""
if [ "$1" == "" ]; then
    echo "No input file provided"
    exit 3
else
    FILE="$1"
    #make sure fine exists and readable
    if [ ! -f $FILE ]; then
        echo "$FILE : does not exist"
        exit 1
    elif [ ! -r $FILE ]; then
        echo "$FILE : cannot read"
        exit 2
    fi
fi
exec 3<&0
exec 0<"$FILE"
while read -d "|" folder
do
    #make folder for repository
    mkdir $folder
    cd $folder
    read -e server

    #checkout repository
    svn co $server . --username=$name --password=$pass

    # initialize vars
    result="asdf"
    stars=""
    star="*/"
    svn=".svn"

    # cleanup repository folders
    while [ "$result" != "" ]
    do
        result=`rm -rfv $stars$svn`
        stars="$stars$star"
    done
    cd ..
done
exec 0<&3

echo "All Done!"
exit 0
